package com.pinxixi.specification.controller;

import com.pinxixi.api.specification.SpecificationControllerApi;
import com.pinxixi.framework.domain.specification.Specification;
import com.pinxixi.framework.domain.specification.SpecificationOption;
import com.pinxixi.framework.domain.specification.ext.SpecificationEntity;
import com.pinxixi.framework.model.response.ListResponseResult;
import com.pinxixi.framework.model.response.QueryResponseResult;
import com.pinxixi.framework.model.response.ResponseResult;
import com.pinxixi.specification.service.SpecificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/specification")
public class SpecificationController implements SpecificationControllerApi {

    @Autowired
    private SpecificationService specificationSerivce;

    @Override
    @GetMapping("/findAll")
    public ListResponseResult<Specification> findAll() {
        return specificationSerivce.findAll();
    }

    @Override
    @GetMapping("/findPage/{page}/{size}")
    public ListResponseResult<Specification> findPage(@PathVariable("page") Integer page,
                                          @PathVariable("size") Integer size,
                                          Specification specification) {
        return specificationSerivce.findPage(page,size,specification);
    }

    @Override
    @GetMapping("/findOne/{id}")
    public QueryResponseResult<SpecificationEntity> findOne(@PathVariable("id") Integer id) {
        return specificationSerivce.findOne(id);
    }

    @Override
    @PostMapping("/save")
    public ResponseResult save(@RequestBody SpecificationEntity entity) {
        return specificationSerivce.save(entity);
    }

    @Override
    @DeleteMapping("/delete/{id}")
    public ResponseResult delete(@PathVariable("id") Integer id) {
        return specificationSerivce.delete(id);
    }

    @Override
    @DeleteMapping("/deleteAll")
    public ResponseResult deleteAll(Integer[] ids) {
        return specificationSerivce.deleteAll(ids);
    }

    @Override
    @GetMapping("/findOptions/{id}")
    public ListResponseResult<SpecificationOption> findOptionsBySpecId(@PathVariable("id") Integer id) {
        return specificationSerivce.findOptionsBySpecId(id);
    }
}
